home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The CICA Windows Explosion!
/
The CICA Windows Explosion! - Disc 2.iso
/
programr
/
vlib250.zip
/
VLIBDEMO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-31
|
56KB
|
2,086 lines
/****************************************************************************
PROGRAM: Vlibdemo.exe
PURPOSE: To demonstrate the usage of Visualib(TM) functions.
PROVIDER: Visual Tech Co.
P.O.Box 8735
Fort Wayne, IN 46898-8735
Tel. (219) 289-0235
Fax. (816) 746-6618
DATE: Januray. 1994
****************************************************************************/
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
#include <math.h>
#include <malloc.h>
#include "visualib.h"
#include "vlibdemo.h"
#include "demoproc.h"
#include "dialogs.h"
HINSTANCE hinst;
char szAppName[] = "VlibDemo"; // The name of this application
char szTitle[] = "Visualib 2.60 Demonstration";
HVIEW viewer21 = 0, viewer22 = 0, viewer31 = 0, viewer32 = 0,
viewer33 = 0, viewer34 = 0, viewer35 = 0;
WORD demo_function, animate_length;
HLITE light1 = 0, light2 = 0, light3 = 0,
light4 = 0, light5 = 0, light6 = 0, light7 = 0, light8 = 0;
HMATE mater1, mater2, mater3, mater4, mater5, mater6, mater7;
BOOL withframe = FALSE;
HGLOBAL hdib1 = NULL, hdib2 = NULL, hdib3 = NULL;
COLORREF backcolor;
HBRUSH backbrush;
HPALETTE hpal;
void FunctionDemos (HDC hdc);
int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR CmdLine, int nCmdShow)
{
MSG msg;
if (hPrev)
return (FALSE);
if (!InitApplication (hInst) || !InitInstance (hInst, nCmdShow))
return (FALSE);
while (GetMessage (&msg, NULL, 0, 0)) {
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return (msg.wParam);
}
void ViewerReset ()
{
RECT port;
if (viewer21) {
SetRect (&port, 10, 10, 110, 110);
SetViewerFrame (viewer21, &port);
SetWindow2D (viewer21, -10, -10, 10, 10);
}
if (viewer22) {
SetRect (&port, 10, 10, 410, 227);
SetViewerFrame (viewer22, &port);
SetWindow2D (viewer22, 0, 0, 1, (REAL) (13.0 / 24.0));
}
if (viewer31) {
SetRect (&port, 120, 10, 220, 110);
SetViewerFrame (viewer31, &port);
SetView3D (viewer31, 100, 100, 100, 0, 0, 0, 0);
SetPerspective (viewer31, 45, 1, 1, 1000);
}
if (viewer32) {
SetRect (&port, 230, 10, 330, 110);
SetViewerFrame (viewer32, &port);
SetView3D (viewer32, 100, 100, 100, 0, 0, 0, 0);
SetPerspective (viewer32, 45, 1, 1, 1000);
}
if (viewer33) {
SetRect (&port, 230, 130, 330, 230);
SetViewerFrame (viewer33, &port);
SetPolarView (viewer33, 1, 1, 0, 20, 75, 45, 0);
SetPerspective (viewer33, 90, 1, 1, 1000);
}
if (viewer34) {
SetRect (&port, 120, 130, 220, 230);
SetViewerFrame (viewer34, &port);
SetPolarView (viewer34, 0, 0, 0, 10, 45, 45, 0);
SetProjection3D (viewer34, -10, -10, 10, 10, 1, 100, VL_ORTHOGONAL);
}
if (viewer35) {
SetRect (&port, 10, 130, 110, 230);
SetViewerFrame (viewer35, &port);
SetPolarView (viewer35, 0, 0, 0, 20, 75, 45, 0);
SetPerspective (viewer35, 90, 1, 1, 80);
}
}
/****************************************************************************
FUNCTION: InitApplication (HANDLE)
****************************************************************************/
BOOL InitApplication (HINSTANCE hInstance)
{
HDC hdc;
WNDCLASS wc;
if (!InitializeVisualib ())
return (FALSE);
hpal = SetRGBPalette ();
SwitchLight (VL_DEFAULT, FALSE);
light1 = NewLight (VL_DISTLIGHT);
if (light1) {
LightCoordinateType (light1, VL_WORLDLIGHT);
SetLightDirection (light1, 5, 1, 4);
LightColor (light1, RGB (255, 255, 255));
SwitchLight (light1, TRUE);
}
light2 = NewLight (VL_POINTLIGHT);
if (light2) {
SetLightLocation (light2, -50, 0, 0);
LightColor (light2, RGB (51, 255, 51));
}
light3 = NewLight (VL_POINTLIGHT);
if (light3) {
SetLightLocation (light3, 250, -20, 0);
LightColor (light3, RGB (51, 51, 255));
}
light4 = NewLight (VL_SPOTLIGHT);
if (light4) {
LightCoordinateType (light4, VL_WORLDLIGHT);
SetLightLocation (light4, 0, 100, 100);
SetLightDirection (light4, 0, -1, -1);
SetSpotlightSpread (light4, 20, 50);
LightColor (light4, RGB (255, 0, 0));
}
light5 = NewLight (VL_SPOTLIGHT);
if (light5) {
LightCoordinateType (light5, VL_WORLDLIGHT);
SetLightLocation (light5, 100, 0, 100);
SetLightDirection (light5, -1, 0, -1);
SetSpotlightSpread (light5, 20, 50);
LightColor (light5, RGB (0, 255, 0));
}
light6 = NewLight (VL_SPOTLIGHT);
if (light6) {
LightCoordinateType (light6, VL_WORLDLIGHT);
SetLightLocation (light6, 100, 100, 100);
SetLightDirection (light6, -1, -1, -1);
SetSpotlightSpread (light6, 20, 50);
LightColor (light6, RGB (0, 0, 255));
}
light7 = NewLight (VL_POINTLIGHT);
if (light7) {
LightCoordinateType (light7, VL_WORLDLIGHT);
SetLightLocation (light7, 250, 0, 0);
LightColor (light7, RGB (255, 255, 255));
}
light8 = NewLight (VL_POINTLIGHT);
if (light8) {
LightCoordinateType (light8, VL_WORLDLIGHT);
SetLightLocation (light8, 350, 150, 350);
LightColor (light8, RGB (255, 255, 255));
}
hdc = GetDC (NULL);
if (GetDeviceCaps (hdc, BITSPIXEL) >= 8) {
ShadingMethod (VL_PHONGSHADE);
DepthBuffer (TRUE);
}
else {
ShadingMethod (VL_FLATSHADE);
DepthBuffer (FALSE);
}
LocalViewer (FALSE);
ReleaseDC (NULL, hdc);
BackFaceRemoval (TRUE);
mater1 = NewMaterial ();
MaterialSpecular (mater1, RGB (255, 255, 255));
MaterialAmbient (mater1, RGB (0, 0, 0));
MaterialDiffuse (mater1, RGB (255, 0, 0));
MaterialShininess (mater1, 50);
mater2 = NewMaterial ();
MaterialSpecular (mater2, RGB (255, 255, 255));
MaterialAmbient (mater2, RGB (25, 25, 25));
MaterialDiffuse (mater2, RGB (0, 255, 0));
MaterialShininess (mater2, 50);
mater3 = NewMaterial ();
MaterialSpecular (mater3, RGB (255, 255, 255));
MaterialAmbient (mater3, RGB (0, 0, 0));
MaterialDiffuse (mater3, RGB (0, 0, 255));
MaterialShininess (mater3, 50);
mater4 = NewMaterial ();
mater5 = NewMaterial ();
mater6 = NewMaterial ();
mater7 = NewMaterial ();
SelectMaterial (mater3);
SetDepthBuffer (VL_DEFAULT);
viewer21 = NewViewer (VL_TWOD);
viewer22 = NewViewer (VL_TWOD);
viewer31 = NewViewer (VL_THREED);
viewer32 = NewViewer (VL_THREED);
viewer33 = NewViewer (VL_THREED);
viewer34 = NewViewer (VL_THREED);
viewer35 = NewViewer (VL_THREED);
ViewerReset ();
demo_function = IDM_DEMO_START;
wc.style = 0;
wc.lpfnWndProc = MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (VL_LOGO));
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
backcolor = RGB (128, 128, 128);
wc.hbrBackground = GetStockObject(GRAY_BRUSH);
wc.lpszMenuName = szAppName;
wc.lpszClassName = szAppName;
return (RegisterClass (&wc));
}
/****************************************************************************
FUNCTION: InitInstance (HANDLE, int)
****************************************************************************/
BOOL InitInstance (HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
int sw, sh, ww, wh;
sw = GetSystemMetrics (0);
sh = GetSystemMetrics (1);
hinst = hInstance;
ww = (int) (sw * 0.8f);
wh = (int) (sh * 0.8f);
sw = (int) (sw / 10);
sh = (int) (sh / 10);
hWnd = CreateWindow (szAppName, szTitle,
WS_OVERLAPPEDWINDOW, sw, sh, ww, wh, NULL, NULL, hInstance, NULL);
if (!hWnd)
return (FALSE);
ShowWindow (hWnd, nCmdShow);
UpdateWindow (hWnd);
PostMessage (hWnd, WM_COMMAND, IDM_DEMO_WITHFRAME, 0L);
return (TRUE);
}
POINT3D surf[16] = {
{-3, 0, 1}, {2, 1, 0}, {5, 0, 0}, {8, 0, 2},
{-2, 2, 3}, {1, 4, 3}, {6, 4, 1}, {7, 2, 1},
{-2, 5, 5}, {1, 7, 3}, {5, 5, 2}, {7, 6, 3},
{-2, 8, 8}, {2, 9, 0}, {4, 7, 4}, {8, 9, 9}
};
REAL sknot[20] = {0, 0, 0, 1, 1, 1, 2, 2, 3, 4, 4, 4};
REAL tknot[20] = {0, 0, 0, 1, 1, 1, 2, 2, 3, 4, 4, 4};
void ObjectMotion2D (HDC hdc)
{
WORD i;
HVIEW hv = viewer21;
SelectViewer (hv);
if (!BeginDoubleBuffer (&hdc))
return;
PenColor (hdc, VL_RED);
for (i = 0; i < 5 * animate_length; i ++) {
CleanViewer (hdc, hv);
BrushColor (hdc, VL_GREEN);
Flower2D (hdc, 0, 0, 0, 6, 6, 10, 4.5f / 6);
BrushColor (hdc, VL_RED);
Star2D (hdc, 0, 0, 0, 4, 4, 5);
Rotate2D (6);
if (!UpdateDoubleBuffer (hdc))
return;
}
for (i = 0; i < 5 * animate_length; i ++) {
CleanViewer (hdc, hv);
BrushColor (hdc, VL_GREEN);
Flower2D (hdc, 0, 0, 0, 6, 6, 10, 4.5f / 6);
BrushColor (hdc, VL_RED);
Star2D (hdc, 0, 0, 0, 4, 4, 5);
MoveViewer2D (hv, 0.25f, 0, TRUE);
if (!UpdateDoubleBuffer (hdc))
return;
}
for (i = 0; i < 5 * animate_length; i ++) {
CleanViewer (hdc, hv);
BrushColor (hdc, VL_GREEN);
Flower2D (hdc, 0, 0, 0, 6, 6, 10, 4.5f / 6);
BrushColor (hdc, VL_RED);
Star2D (hdc, 0, 0, 0, 4, 4, 5);
Scale2D ((REAL)1.06, (REAL)1.06);
if (!UpdateDoubleBuffer (hdc))
return;
}
EndDoubleBuffer (&hdc);
ViewerName (hv, "2D Object Motion");
}
void ViewerMotion3D (HDC hdc)
{
WORD i;
HVIEW hv = viewer31;
SelectViewer (hv);
if (!BeginDoubleBuffer (&hdc))
return;
SelectMaterial (mater1);
for (i = 0; i < 3 * animate_length; i ++) {
MoveViewer3D (hv, 0, 0, -10, TRUE);
CleanViewer (hdc, hv);
if (!Cube (hdc, 50, 50, 25))
goto exit;
UpdateDoubleBuffer (hdc);
}
SelectMaterial (mater2);
for (i = 0; i < 3 * animate_length; i ++) {
MoveViewer3D (hv, 0, 5, 0, TRUE);
CleanViewer (hdc, hv);
if (!Cube (hdc, 50, 50, 25))
goto exit;
UpdateDoubleBuffer (hdc);
}
SelectMaterial (mater3);
for (i = 0; i < 3 * animate_length; i ++) {
MoveViewer3D (hv, 5, 0, 0, TRUE);
CleanViewer (hdc, hv);
if (!Cube (hdc, 50, 50, 25))
goto exit;
UpdateDoubleBuffer (hdc);
}
SelectMaterial (VL_DEFAULT);
for (i = 0; i < 5 * animate_length; i ++) {
RotateViewer3D (hv, 6, 'z', FALSE);
CleanViewer (hdc, hv);
if (!Cube (hdc, 50, 50, 25) || !UpdateDoubleBuffer (hdc))
goto exit;
}
SelectMaterial (mater1);
for (i = 0; i < 5 * animate_length; i ++) {
CleanViewer (hdc, hv);
RotateViewer3D (hv, 6, 'y', FALSE);
if (!Cube (hdc, 50, 50, 25) || !UpdateDoubleBuffer (hdc))
goto exit;
}
SelectMaterial (mater2);
for (i = 0; i < 5 * animate_length; i ++) {
CleanViewer (hdc, hv);
RotateViewer3D (hv, 6, 'x', FALSE);
if (!Cube (hdc, 50, 50, 25) || !UpdateDoubleBuffer (hdc))
goto exit;
}
exit:
EndDoubleBuffer (&hdc);
ViewerName (hv, "Viewer Motion");
}
void ObjectMotion3D (HDC hdc)
{
WORD i;
HVIEW hv = viewer32;
SelectViewer (hv);
if (!BeginDoubleBuffer (&hdc))
return;
SelectMaterial (mater1);
for (i = 0; i <= 5 * animate_length; i ++) {
CleanViewer (hdc, hv);
if (!Cylinder (hdc, 30, 40, 50))
break;
Rotate3D (3, 'z');
Rotate3D (6, 'x');
Rotate3D (3, 'y');
if (!UpdateDoubleBuffer (hdc))
return;
}
EndDoubleBuffer (&hdc);
ViewerName (hv, "Object Motion");
}
void ViewerZoom3D (HDC hdc)
{
WORD i;
HVIEW hv = viewer33;
POINT3D p = {0, 0, 0};
SelectViewer (hv);
BeginDoubleBuffer (&hdc);
SelectMaterial (mater2);
for (i = 0; i < 5 * animate_length; i ++) {
CleanViewer (hdc, hv);
if (!Cone (hdc, 3, 5, 10))
break;
ZoomViewer3D (hv, 1.05f);
UpdateDoubleBuffer (hdc);
}
EndDoubleBuffer (&hdc);
ViewerName (hv, "Viewer Zoom");
}
void RotateStar (HDC hdc)
{
WORD i;
HVIEW hv = viewer35;
SelectViewer (hv);
SelectMaterial (mater1);
if (!BeginDoubleBuffer (&hdc))
return;
for (i = 0; i < 5 * animate_length; i ++) {
CleanViewer (hdc, hv);
if (!SolidStar (hdc, 5, 20, 20, 5))
break;
MoveViewer3D (hv, 0, 0, -0.5f, TRUE);
Rotate3D (6 * i, 'z');
if (!UpdateDoubleBuffer (hdc))
return;
}
EndDoubleBuffer (&hdc);
ViewerName (hv, "Rotate Star");
}
void Object3D (HDC hdc)
{
WORD i;
HVIEW hv = viewer31;
SelectViewer (hv);
if (!BeginDoubleBuffer (&hdc))
return;
Scale3D (20, 20, 20);
for (i = 0; i < 5 * animate_length; i ++) {
CleanViewer (hdc, hv);
PenColor (hdc, VL_GREEN);
Spring (hdc, 3, 2, 0.5f);
PenColor (hdc, VL_NONE);
Translate3D (0.05f, 0, 0);
Rotate3D (-6, 'y');
PushTransformation3D (NULL);
SelectMaterial (mater3);
Rotate3D (6 * i, 'z');
Translate3D (0, 2, 0);
Rotate3D (3, 'y');
if (!Tetrahedron (hdc, 1))
break;
PushTransformation3D (NULL);
SelectMaterial (mater1);
Rotate3D (6, 'x');
Translate3D (0, 0, 2);
Rotate3D (3 * i, 'z');
if (!Octahedron (hdc, 1))
break;
PopTransformation3D (NULL);
PopTransformation3D (NULL);
if (!UpdateDoubleBuffer (hdc))
break;
}
EndDoubleBuffer (&hdc);
ViewerName (hv, "3D Curve");
}
void RotateFrame (HDC hdc)
{
WORD i;
HVIEW hv = viewer32;
REAL point[] = {0, 0, 0, 1, 1, -1, 1, 1, 1, -1, -1, 1, -1, 1, -1,
1, -1, -1, 1, 1, 1, 1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1,
-1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, 1,
0, 0, 0, 1, -1, 1, -1, -1, -1, 0, 0, 0};
SelectViewer (hv);
if (!BeginDoubleBuffer (&hdc))
return;
Scale3D (30, 30, 30);
PenColor (hdc, VL_BLUE);
for (i = 0; i < 5 * animate_length; i++) {
CleanViewer (hdc, hv);
Polyline3D (hdc, VL_3D, point, 19);
Rotate3D (6, 'z');
if (!UpdateDoubleBuffer (hdc))
break;
}
EndDoubleBuffer (&hdc);
ViewerName (hv, "Rotate Frame");
}
void RotateSurface (HDC hdc)
{
WORD i;
HVIEW hv = viewer35;
SelectViewer (hv);
ViewerName (hv, "NURBS Surface");
SelectMaterial (mater2);
if (!BeginDoubleBuffer (&hdc))
return;
TwoSideShading (TRUE);
for (i = 0; i < 5 * animate_length; i++) {
CleanViewer (hdc, hv);
if (!NURBSSurface (hdc, VL_3D, (VECTOR) surf, 4, 4, sknot, tknot, 8, 8))
break;
Rotate3D (6, 'z');
Rotate3D (12, 'x');
Rotate3D (3, 'y');
if (!UpdateDoubleBuffer (hdc))
break;
}
EndDoubleBuffer (&hdc);
}
void RotateDodecahedron (HDC hdc)
{
WORD i;
HVIEW hv = viewer33;
SelectViewer (hv);
ViewerName (hv, "Dodecahedron");
SelectMaterial (mater2);
if (!BeginDoubleBuffer (&hdc))
return;
Scale3D (6, 6, 6);
for (i = 0; i < 5 * animate_length; i ++) {
CleanViewer (hdc, hv);
if (!Dodecahedron (hdc, 0.5f))
break;
Translate3D (0, 0.1f, 0);
Rotate3D (6, 'z');
if (!UpdateDoubleBuffer (hdc))
break;
}
EndDoubleBuffer (&hdc);
}
void RotateIcosahedron (HDC hdc)
{
WORD i;
HVIEW hv = viewer34;
SelectViewer (hv);
ViewerName (hv, "Icosahedron");
SelectMaterial (mater1);
if (!BeginDoubleBuffer (&hdc))
return;
Scale3D (3, 3, 3);
for (i = 0; i < 5 * animate_length; i ++) {
CleanViewer (hdc, hv);
if (!Icosahedron (hdc, 1))
break;
Rotate3D (3, 'y');
Translate3D (0.1f, 0, 0);
Rotate3D (6, 'z');
if (!UpdateDoubleBuffer (hdc))
break;
}
EndDoubleBuffer (&hdc);
}
void AnimationDemo (HDC hdc, WORD cmd)
{
BOOL depthbuffer, shadingmethod, twosideshade, backfaceremoval;
BOOL l0, l1, l2, l3;
l0 = SwitchLight (VL_DEFAULT, FALSE);
l1 = SwitchLight (light1, FALSE);
l2 = SwitchLight (light2, FALSE);
l3 = SwitchLight (light3, FALSE);
depthbuffer = DepthBuffer (FALSE);
shadingmethod = ShadingMethod (VL_FLATSHADE);
twosideshade = TwoSideShading (FALSE);
backfaceremoval = BackFaceRemoval (TRUE);
SwitchLight (light7, TRUE);
SwitchLight (light8, TRUE);
PenColor (hdc, VL_NONE);
switch (cmd) {
case IDM_ANIMATE_FRAME:
animate_length = 10;
RotateFrame (hdc);
break;
case IDM_ANIMATE_OBJECT2D:
animate_length = 10;
ObjectMotion2D (hdc);
break;
case IDM_ANIMATE_SURFACE:
animate_length = 10;
RotateSurface (hdc);
break;
case IDM_ANIMATE_ICOSAHEDRON:
animate_length = 10;
RotateIcosahedron (hdc);
break;
case IDM_ANIMATE_OBJECT3D:
animate_length = 20;
Object3D (hdc);
break;
case IDM_ANIMATE_STAR3D:
animate_length = 15;
RotateStar (hdc);
break;
case IDM_ANIMATE_DODECAHEDRON:
animate_length = 15;
RotateDodecahedron (hdc);
break;
case IDM_ANIMATE_VIEWER3D:
animate_length = 7;
ViewerMotion3D (hdc);
break;
case IDM_ANIMATE_ZOOM3D:
animate_length = 15;
ViewerZoom3D (hdc);
break;
}
SwitchLight (light7, FALSE);
SwitchLight (light8, FALSE);
DepthBuffer (depthbuffer);
ShadingMethod (shadingmethod);
TwoSideShading (twosideshade);
BackFaceRemoval (backfaceremoval);
SwitchLight (VL_DEFAULT, l0);
SwitchLight (light1, l1);
SwitchLight (light2, l2);
SwitchLight (light3, l3);
}
void CompositeDemo2D (HDC hdc)
{
RECT orgport, newport;
HVIEW hv = viewer22;
SelectViewer (hv);
ViewerName (hv, "Flag");
SetRect (&newport, 350, 230, 410, 260);
GetViewerFrame (hv, &orgport);
SetViewerFrame (hv, &newport);
USFlag (hdc);
TextColor (hdc, VL_BLUE, VL_NONE);
DisplayViewerName (hdc, hv, 0);
SetViewerFrame (hv, &orgport);
USFlag (hdc);
}
void Surfaces (HDC hdc, WORD cmd)
{
BOOL twosideshade;
SelectViewer (VL_DEFAULT);
ClearDepthBuffer (0xffff);
twosideshade = TwoSideShading (TRUE);
PenColor (hdc, VL_NONE);
PushTransformation3D (NULL);
switch (cmd) {
case IDM_SURFACE_BEZIER:
{
POINT3D surf[16] = {
{0, 6, 3}, {2, 6, 0}, {4, 6, 2}, {6, 6, 0},
{0, 4, 0}, {2, 4, 5}, {4, 4, 0}, {6, 4, 6},
{0, 2, 5}, {2, 2, 0}, {4, 2, 6}, {6, 2, 0},
{0, 0, 0}, {2, 0, 3}, {4, 0, 0}, {6, 0, 3}};
Scale3D (5, 5, 5);
BezierSurface (hdc, VL_3D, (VECTOR) surf, 16, 16);
PenColor (hdc, VL_GREEN);
Net3D (hdc, VL_3D, (VECTOR) surf, 4, 4);
PolyMark3D (hdc, VL_3D, (VECTOR) surf, 16, 2, 2, VL_CIRCLEMARK);
ViewerName (VL_CURRENT, "Bezier Surface");
break;
}
case IDM_SURFACE_HERMIT:
{
POINT3D surf[16] = {
{0, 0, 0}, {0, 6, 0}, {0, 6, 6}, {0, 6, -2},
{6, 0, 0}, {6, 6, 0}, {0, 2, 2}, {0, 6, -2},
{2, 0, 2}, {2, 0, 2}, {0, 0, 0}, {0, 0, 0},
{2, 0, 2}, {2, 0, 2}, {0, 0, 0}, {0, 0, 0}};
Scale3D (5, 5, 5);
HermitSurface (hdc, VL_3D, (VECTOR) surf, 16, 16);
ViewerName (VL_CURRENT, "Hermit Surface");
break;
}
case IDM_SURFACE_BSPLINE:
{
POINT3D surf[36] = {
{0,0,0},{1,0,0},{2,0,0},{3,0,0},{4,0,0},{5,0,0},
{0,1,0},{1,1,0},{2,1,0},{3,1,0},{4,1,0},{5,1,0},
{0,2,0},{1,2,0},{2,2,9},{3,2,9},{4,2,0},{5,2,0},
{0,3,0},{1,3,0},{2,3,9},{3,3,9},{4,3,0},{5,3,0},
{0,4,0},{1,4,0},{2,4,0},{3,4,0},{4,4,0},{5,4,0},
{0,5,0},{1,5,0},{2,5,0},{3,5,0},{4,5,0},{5,5,0}};
Scale3D (3, 3, 3);
BSplineSurface (hdc, VL_3D, (VECTOR) surf, 6, 6, 4, 4);
ViewerName (VL_CURRENT, "B-Spline Surface");
break;
}
case IDM_SURFACE_NURBS:
{
POINT3D surf[36] = {
{0,0,0},{1,0,0},{2,0,0},{3,0,0},{4,0,0},{5,0,0},
{0,1,0},{1,1,0},{2,1,0},{3,1,0},{4,1,0},{5,1,0},
{0,2,0},{1,2,0},{2,2,9},{3,2,9},{4,2,0},{5,2,0},
{0,3,0},{1,3,0},{2,3,9},{3,3,9},{4,3,0},{5,3,0},
{0,4,0},{1,4,0},{2,4,0},{3,4,0},{4,4,0},{5,4,0},
{0,5,0},{1,5,0},{2,5,0},{3,5,0},{4,5,0},{5,5,0}};
REAL sknot[20] = {0,0,0,1,2,3,3,3};
REAL tknot[20] = {0,0,0,1,2,3,3,3};
Scale3D (10, 10, 5);
Translate3D (-3, -2, 0);
NURBSSurface (hdc, VL_3D, (VECTOR) surf, 6, 6, sknot, tknot, 4, 4);
PenColor (hdc, VL_GREEN);
Net3D (hdc, VL_3D, (VECTOR) surf, 6, 6);
PolyMark3D (hdc, VL_3D, (VECTOR) surf, 36, 2, 2, VL_BOXMARK);
ViewerName (VL_CURRENT, "NURBS Surface");
break;
}
case IDM_SURFACE_COONSPATCH:
{
POINT3D point[] = {{0,0,4},{1,-2,3},{2,-2,2},{3,0,1},
{4,0,0},{4,1,0},{4,2,0},{4,3,0},
{4,4,0},{3,4,0},{2,4,0},{1,4,0},
{0,4,0},{0,3,1},{-2,2,2},{-2,1,3}};
Scale3D (5, 5, 5);
CoonsPatch (hdc, VL_3D, (VECTOR) point, 5, 5);
ViewerName (VL_CURRENT, "Coons Patch Surface");
break;
}
case IDM_SURFACE_REVOLSPLINE:
{
POINT3H revcurv[10] = {
{0.7,0.7,-7,1},{1.2,1.2,-4,1},{0.8,0.8,-2.5,1},
{0.6,0.6,-1.5,1},{0.4,0.4,-0.5,1},{0.3,0.3,4,1},
{0.55,0.55,4.5,1}
};
Scale3D (10, 10, 5);
Translate3D (-3, -2, 0);
RevolveBSpline(hdc, VL_3H, (VECTOR)revcurv, 7, 12, TWOPI);
break;
}
}
PopTransformation3D (NULL);
TwoSideShading (twosideshade);
}
void PolyfacetsDemo (HDC hdc)
{
WORD i;
LPINT vindex, nindex;
LPWIRE wire;
LPFACET facet;
LPVECT3 normal;
POLYFACET polyfacet;
LPPOINT3D vertex;
polyfacet.nvert = 8;
polyfacet.nnorm = 4;
polyfacet.nwire = 12;
polyfacet.nfacet = 6;
polyfacet.vertex = NEWLIST (POINT3D, polyfacet.nvert);
wire = polyfacet.wire = NEWLIST (WIRE, polyfacet.nwire);
facet = polyfacet.facet = NEWLIST (FACET, polyfacet.nfacet);
normal = polyfacet.normal = NEWLIST (VECTOR3, 4);
VSET3 (normal[0], 0.6f, -0.8f, 0);
VSET3 (normal[1], 0.6f, 0.8f, 0);
VSET3 (normal[2], 0, 0.6f, 0.8f);
VSET3 (normal[3], 0, 0.6f, -0.8f);
vertex = polyfacet.vertex;
SetPoint3D (&vertex[0], 0, 0, 20);
SetPoint3D (&vertex[1], 20, 0, 20);
SetPoint3D (&vertex[2], 20, 20, 20);
SetPoint3D (&vertex[3], 0, 20, 20);
SetPoint3D (&vertex[4], 0, 0, 0);
SetPoint3D (&vertex[5], 20, 0, 0);
SetPoint3D (&vertex[6], 20, 20, 0);
SetPoint3D (&vertex[7], 0, 20, 0);
wire[3].vert2 = wire[0].vert1 = wire[4].vert1 = 0;
wire[0].vert2 = wire[1].vert1 = wire[5].vert1 = 1;
wire[1].vert2 = wire[2].vert1 = wire[6].vert1 = 2;
wire[2].vert2 = wire[3].vert1 = wire[7].vert1 = 3;
wire[11].vert2 = wire[4].vert2 = wire[8].vert1 = 4;
wire[8].vert2 = wire[5].vert2 = wire[9].vert1 = 5;
wire[9].vert2 = wire[6].vert2 = wire[10].vert1 = 6;
wire[10].vert2 = wire[7].vert2 = wire[11].vert1 = 7;
facet[0].npts = facet[1].npts = facet[2].npts = facet[3].npts = 4;
facet[4].npts = facet[5].npts = 4;
facet[0].nindex = facet[1].nindex = facet[4].nindex = facet[5].nindex = 0;
nindex = facet[2].nindex = NEWLIST (INT, 4);
VSET4 (nindex, 0, 0, 1, 1);
nindex = facet[3].nindex = NEWLIST (INT, 4);
VSET4 (nindex, 2, 3, 3, 2);
vindex = facet[0].vindex = NEWLIST (INT, 4);
VSET4 (vindex, 0, 1, 2, 3);
VSET3 (facet[0].normal, 0, 0, 1);
vindex = facet[1].vindex = NEWLIST (INT, 4);
VSET4 (vindex, 0, 4, 5, 1);
VSET3 (facet[1].normal, 0, -1, 0);
vindex = facet[2].vindex = NEWLIST (INT, 4);
VSET4 (vindex, 1, 5, 6, 2);
VSET3 (facet[2].normal, 1, 0, 0);
vindex = facet[3].vindex = NEWLIST (INT, 4);
VSET4 (vindex, 2, 6, 7, 3);
VSET3 (facet[3].normal, 0, 1, 0);
vindex = facet[4].vindex = NEWLIST (INT, 4);
VSET4 (vindex, 3, 7, 4, 0);
VSET3 (facet[4].normal, -1, 0, 0);
vindex = facet[5].vindex = NEWLIST (INT, 4);
VSET4 (vindex, 4, 7, 6, 5);
VSET3 (facet[5].normal, 0, 0, -1);
ClearDepthBuffer (0xffff);
SelectMaterial (mater2);
SwitchLight (light7, TRUE);
SwitchLight (light8, TRUE);
ShadePolyFacet (hdc, &polyfacet);
for (i = 0; i < polyfacet.nfacet; i++) {
FREE (facet[i].vindex);
if (facet[i].nindex)
FREE (facet[i].nindex);
}
FREE (polyfacet.vertex);
FREE (polyfacet.normal);
FREE (polyfacet.wire);
FREE (polyfacet.facet);
}
VOIDED ShowSolidPrimitives (HDC hdc, WORD cmd)
{
BackFaceRemoval (TRUE);
TwoSideShading (FALSE);
ClearDepthBuffer (0xffff);
PenColor (hdc, VL_NONE);
switch (cmd) {
case IDM_SOLID_TUBE:
ViewerName (VL_CURRENT, "Tube and Ring");
Tube (hdc, 15, 20, 2, 30);
SolidRing (hdc, 40, 40, 3, 10, 115, 335, 1);
break;
case IDM_SOLID_TORUS:
ViewerName (VL_CURRENT, "Torus and Wedged Torus");
TranslateTo3D (-20, 20, 0);
if (!Torus (hdc, 15, 5))
break;
TranslateTo3D (20, -20, 0);
WedgedTorus (hdc, 15, 5, 90, 360, 180, 90);
break;
case IDM_SOLID_SPHERE:
ViewerName (VL_CURRENT, "Sphere and Wedged Sphere");
WedgedSphere (hdc, 20, 20, 30, 90, 0, 45, 135);
break;
case IDM_SOLID_ELLIPSOID:
ViewerName (VL_CURRENT, "Ellipsoid");
Ellipsoid (hdc, 20, 40, 30);
break;
case IDM_SOLID_CYLINDER:
ViewerName (VL_CURRENT, "Cylinder and Solid Pie");
if (!WedgedCylinder (hdc, 10, 20, 30, 0.7f, 90, 0))
break;
TranslateTo3D (30, -30, 0);
if (!SolidPie (hdc, 20, 10, 5, 45, 180))
break;
TranslateTo3D (-30, 30, 0);
SolidPie (hdc, 20, 10, 5, 180, 45);
break;
case IDM_SOLID_CONE:
ViewerName (VL_CURRENT, "Cone and Wedged Cone");
if (!WedgedCone (hdc, 10, 20, 30, 90, 0))
break;
TranslateTo3D (30, -30, 0);
if (!WedgedCone (hdc, 20, 10, 30, 110, 0))
break;
TranslateTo3D (-30, 30, 0);
WedgedCone (hdc, 20, 10, 30, 180, 45);
break;
case IDM_SOLID_TETRAHEDRON:
ViewerName (VL_CURRENT, "Tetrahedron (4 facets)");
Tetrahedron (hdc, 20);
MarkPosition3D (hdc, 0, 0, 0, 10, VL_CROSSHAIR);
break;
case IDM_SOLID_OCTAHEDRON:
ViewerName (VL_CURRENT, "Octahedron (8 facets)");
Octahedron (hdc, 20);
MarkPosition3D (hdc, 0, 0, 0, 20, VL_ORIGIN);
break;
case IDM_SOLID_DODECAHEDRON:
ViewerName (VL_CURRENT, "Dodecahedron (12 facets)");
Dodecahedron (hdc, 20);
MarkPosition3D (hdc, 0, 0, 0, 10, VL_ORIGIN);
break;
case IDM_SOLID_ICOSAHEDRON:
ViewerName (VL_CURRENT, "Icosahedron (20 facets)");
Icosahedron (hdc, 20);
MarkPosition3D (hdc, 0, 0, 0, 10, VL_ORIGIN);
break;
case IDM_SOLID_FRUSTUM:
ViewerName (VL_CURRENT, "Frustum");
Frustum (hdc, 20, 30, 10, 20, 20);
break;
case IDM_SOLID_RIDGE:
ViewerName (VL_CURRENT, "Ridge");
Ridge (hdc, 20, 30, 10, 20);
break;
case IDM_SOLID_BOX:
ViewerName (VL_CURRENT, "Box");
Cube (hdc, 40, 40, 20);
break;
case IDM_SOLID_STAR:
ViewerName (VL_CURRENT, "Solid Star");
SolidStar (hdc, 5, 20, 20, 10);
break;
case IDM_SOLID_FLOWER:
ViewerName (VL_CURRENT, "Solid Flower");
SolidFlower (hdc, 8, 0.666f, 30, 30, 10);
break;
}
}
void ShadingSettings (HWND hwnd, WORD cmd)
{
COLORREF color;
switch (cmd) {
case IDM_OPTION_PREVIEW:
{
RECT rect = {50, 50, 100, 100};
HDC hdc;
SelectViewer (VL_DEFAULT);
hdc = GetDC (hwnd);
ShadingPreview (hdc, &rect, 40, 173);
ReleaseDC (hwnd, hdc);
break;
}
case IDM_GLOBAL_AMBIENT:
color = SelectColor (AmbientColor (VL_INQUIRE));
AmbientColor (color);
break;
#ifndef WIN32
case IDM_OPTION_BACKCOLOR:
{
HBRUSH hbrush = hbrush = GetClassWord (hwnd, GCW_HBRBACKGROUND);
backcolor = SelectColor (backcolor);
DeleteObject (hbrush);
hbrush = CreateSolidBrush (backcolor);
SetClassWord (hwnd, GCW_HBRBACKGROUND, hbrush);
InvalidateRect (hwnd, NULL, TRUE);
UpdateWindow (hwnd);
break;
}
#endif
case IDM_OPTION_REDRAW:
InvalidateRect (hwnd, NULL, TRUE);
UpdateWindow (hwnd);
break;
case IDM_OPTION_SHADEMODE:
DialogBox (hinst, MAKEINTRESOURCE(DLGSHADING), hwnd, DlgShading);
break;
case IDM_SELECT_M1:
SelectMaterial (VL_DEFAULT);
DialogBox (hinst, MAKEINTRESOURCE(DLGMATERIAL), hwnd, DlgMaterial);
break;
case IDM_SELECT_M2:
SelectMaterial (mater1);
DialogBox (hinst, MAKEINTRESOURCE(DLGMATERIAL), hwnd, DlgMaterial);
break;
case IDM_SELECT_M3:
SelectMaterial (mater2);
DialogBox (hinst, MAKEINTRESOURCE(DLGMATERIAL), hwnd, DlgMaterial);
break;
case IDM_SELECT_M4:
SelectMaterial (mater3);
DialogBox (hinst, MAKEINTRESOURCE(DLGMATERIAL), hwnd, DlgMaterial);
break;
case IDM_SELECT_L1:
SelectLight (VL_DEFAULT);
DialogBox (hinst, MAKEINTRESOURCE(DLGLIGHTSETUP), hwnd, DlgLightSetup);
break;
case IDM_SELECT_L2:
SelectLight (light1);
DialogBox (hinst, MAKEINTRESOURCE(DLGLIGHTSETUP), hwnd, DlgLightSetup);
break;
case IDM_SELECT_L3:
SelectLight (light2);
DialogBox (hinst, MAKEINTRESOURCE(DLGLIGHTSETUP), hwnd, DlgLightSetup);
break;
case IDM_SELECT_L4:
SelectLight (light3);
DialogBox (hinst, MAKEINTRESOURCE(DLGLIGHTSETUP), hwnd, DlgLightSetup);
break;
case IDM_OPTION_TEXTURE:
DialogBox (hinst, MAKEINTRESOURCE(DLGTEXTURE), hwnd, DlgTexture);
break;
}
}
WORD halign = TA_CENTER;
WORD valign = TA_BASELINE;
VOIDED ShowTextPrimitives (HDC hdc, WORD func)
{
char str[40];
BackFaceRemoval (TRUE);
TwoSideShading (FALSE);
wsprintf (str, "Visualib\nAdvanced\nTechnology");
switch (func) {
case IDM_TEXT_2D:
SelectViewer (VL_DEFAULT2D);
SetTextHeight (4);
BrushColor (hdc, VL_RED);
PenColor (hdc, VL_GREEN);
SetTextAlign (hdc, halign | valign);
Text2D (hdc, 0, 0, 0, str);
ViewerName (VL_CURRENT, "2D Horizontal Text");
break;
case IDM_TEXT_3D:
SelectViewer (VL_DEFAULT);
MarkPosition3D (hdc, 0, 0, 0, 40, VL_ORIGIN);
PushTransformation3D (NULL);
SetTextHeight (15);
BrushColor (hdc, VL_YELLOW);
PenColor (hdc, VL_BLUE);
SetTextAlign (hdc, TA_LEFT | TA_BOTTOM);
Text3D (hdc, 3, 1, 0, str);
PushTransformation3D (NULL);
Rotate3D (90, 'y');
SetTextAlign (hdc, TA_RIGHT | TA_BOTTOM);
Text3D (hdc, -3, 1, 0, str);
PopTransformation3D (NULL);
Rotate3D (-90, 'x');
SetTextAlign (hdc, TA_TOP | TA_LEFT);
Text3D (hdc, 3, -1, 0, str);
PopTransformation3D (NULL);
ViewerName (VL_CURRENT, "3D Horizontal Text");
break;
case IDM_TEXT_SOLID:
SelectViewer (VL_DEFAULT);
SetTextHeight (30);
ClearDepthBuffer (0xffff);
SetTextThickness (8);
PushTransformation3D (NULL);
Rotate3D (135, 'z');
Rotate3D (30, 'x');
SetTextAlign (hdc, TA_BASELINE | TA_CENTER);
SolidText (hdc, str);
PopTransformation3D (NULL);
ViewerName (VL_CURRENT, "Solid Text");
break;
}
}
void ProcessWindowPaint (HWND hwnd)
{
PAINTSTRUCT ps;
HDC hdc;
hdc = BeginPaint (hwnd, &ps);
if (hpal) {
SelectPalette (hdc, hpal, FALSE);
RealizePalette (hdc);
}
FunctionDemos (hdc);
EndPaint (hwnd, &ps);
}
void SpotlightDemo (HDC hdc)
{
SelectViewer (VL_DEFAULT);
ViewerName (VL_CURRENT, "Spot Lights Demo");
ClearDepthBuffer (0xffff);
SelectMaterial (VL_DEFAULT);
SwitchLight (light4, TRUE);
SwitchLight (light5, TRUE);
SwitchLight (light6, TRUE);
SolidFlower (hdc, 8, 0.666f, 30, 30, 10);
}
void ImageMappingDemo (HDC hdc)
{
REAL point[12];
static BOOL LoadImage = TRUE;
char filename[128];
if (LoadImage) {
if (GetDeviceCaps (hdc, BITSPIXEL) >= 8)
lstrcpy (filename, "deer256.bmp");
else
lstrcpy (filename, "bring16.bmp");
if (!ReadDIBFile (filename, &hdib1) && !ReadDIBFile (NULL, &hdib1))
return;
if (!ReadDIBFile (filename, &hdib2) && !ReadDIBFile (NULL, &hdib2))
return;
GetSystemDirectory (filename, 128);
lstrcat (filename, "\\vgalogo.rle");
if (!ReadDIBFile (filename, &hdib3) && !ReadDIBFile (NULL, &hdib3))
return;
LoadImage = FALSE;
}
SelectViewer (VL_DEFAULT);
ViewerName (VL_CURRENT, "Image Mapping");
Scale3D (20, 20, 30);
point[0] = -1; point[1] = -1; point[2] = 1;
point[3] = 1; point[4] = -1; point[5] = 1;
point[6] = 1; point[7] = 1; point[8] = 1;
point[9] = -1; point[10] = 1; point[11] = 1;
if (hdib1 && !ImageMap3D (hdc, hdib1, VL_3D, point))
return;
point[0] = 1; point[1] = 1; point[2] = 1;
point[3] = 1; point[4] = 1; point[5] = -1;
point[6] = -1; point[7] = 1; point[8] = -1;
point[9] = -1; point[10] = 1; point[11] = 1;
if (hdib2 && !ImageMap3D (hdc, hdib2, VL_3D, point))
return;
point[0] = 1; point[1] = -1; point[2] = -1;
point[3] = 1; point[4] = 1; point[5] = -1;
point[6] = 1; point[7] = 1; point[8] = 1;
point[9] = 1; point[10] = -1; point[11] = 1;
if (hdib3)
ImageMap3D (hdc, hdib3, VL_3D, point);
}
void TranslateTransf2D (HDC hdc)
{
SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
ViewerName (VL_CURRENT, "2D Translate Transformation");
BrushColor (hdc, VL_RED);
Star2D (hdc, 0, 0, 0, 2, 2, 5);
Label2D (hdc, 0, 0, "Original");
TranslateTo2D (5, 3);
BrushColor (hdc, VL_GREEN);
Star2D (hdc, 0, 0, 0, 2, 2, 5);
Label2D (hdc, 0, 0, "Translated To (5,3)");
PushTransformation2D (NULL);
Translate2D (0, -6);
BrushColor (hdc, VL_YELLOW);
Star2D (hdc, 0, 0, 0, 2, 2, 5);
Label2D (hdc, 0, 0, "Translated (0,-6) from above");
PopTransformation2D (NULL);
Translate2D (-10, 0);
BrushColor (hdc, VL_BLUE);
Star2D (hdc, 0, 0, 0, 2, 2, 5);
Label2D (hdc, 0, 0, "Translated (-10,0) from right");
Translate2D (0, -6);
BrushColor (hdc, VL_WHITE);
Star2D (hdc, 0, 0, 0, 2, 2, 5);
Label2D (hdc, 0, 0, "Translated (0,-6) from above");
}
void MirrorTransf2D (HDC hdc)
{
SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
ViewerName (VL_CURRENT, "2D Mirror Transformation");
BrushColor (hdc, VL_RED);
Star2D (hdc, 5, 3, 0, 2, 2, 5);
Label2D (hdc, 5, 3, "Original");
PushTransformation2D (NULL);
Mirror2D (0, 0, 0);
BrushColor (hdc, VL_GREEN);
Star2D (hdc, 5, 3, 0, 2, 2, 5);
Label2D (hdc, 5, 3, "Mirrored along (0,0) with 0 degree");
PopTransformation2D (NULL);
PushTransformation2D (NULL);
Mirror2D (0, 0, 90);
BrushColor (hdc, VL_YELLOW);
Star2D (hdc, 5, 3, 0, 2, 2, 5);
Label2D (hdc, 5, 3, "Mirrored along (0,0) with 90 degree");
PopTransformation2D (NULL);
PushTransformation2D (NULL);
Mirror2D (0, 0, (REAL)(atan2 (-5, 3) * RTOD));
BrushColor (hdc, VL_BLUE);
Star2D (hdc, 5, 3, 0, 2, 2, 5);
Label2D (hdc, 5, 3, "Mirrored along (0,0) with radian (-5,3)");
PopTransformation2D (NULL);
}
void StretchTransf2D (HDC hdc)
{
SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
ViewerName (VL_CURRENT, "2D Stretch Transformation");
BrushColor (hdc, VL_RED);
Star2D (hdc, 0, 0, 0, 2, 2, 5);
Label2D (hdc, 0, 0, "Original");
PushTransformation2D (NULL);
Stretch2D (5, 3, 0, 1.5f);
BrushColor (hdc, VL_GREEN);
Star2D (hdc, 5, 3, 0, 2, 2, 5);
Label2D (hdc, 5, 3, "Stretched along 0 degree");
PopTransformation2D (NULL);
PushTransformation2D (NULL);
Stretch2D (5, -3, 90, 1.5f);
BrushColor (hdc, VL_YELLOW);
Star2D (hdc, 5, -3, 0, 2, 2, 5);
Label2D (hdc, 5, -3, "Stretched along 90 degree");
PopTransformation2D (NULL);
PushTransformation2D (NULL);
Stretch2D (-5, -3, 45, 1.5f);
BrushColor (hdc, VL_BLUE);
Star2D (hdc, -5, -3, 0, 2, 2, 5);
Label2D (hdc, -5, -3, "Stretched along 45 degree");
PopTransformation2D (NULL);
PushTransformation2D (NULL);
Stretch2D (-5, 3, 45, -1.5f);
BrushColor (hdc, VL_BROWN);
Star2D (hdc, -5, 3, 0, 2, 2, 5);
Label2D (hdc, -5, 3, "Stretched and flipped 45 degree");
PopTransformation2D (NULL);
}
void ShearTransf2D (HDC hdc)
{
SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
ViewerName (VL_CURRENT, "2D Shear Transformation");
BrushColor (hdc, VL_RED);
Star2D (hdc, 0, 0, 0, 2, 2, 5);
Label2D (hdc, 0, 0, "Original");
PushTransformation2D (NULL);
Shear2D (5, 3, 0, 0.5f, 0);
BrushColor (hdc, VL_GREEN);
Star2D (hdc, 5, 3, 0, 2, 2, 5);
Label2D (hdc, 5, 3, "Horizontal shear");
PopTransformation2D (NULL);
PushTransformation2D (NULL);
Shear2D (5, -3, 0, 0, 0.5f);
BrushColor (hdc, VL_BLUE);
Star2D (hdc, 5, -3, 0, 2, 2, 5);
Label2D (hdc, 5, -3, "Vertical shear");
PopTransformation2D (NULL);
PushTransformation2D (NULL);
Shear2D (-5, -3, 0, 0.5f, 0.5f);
BrushColor (hdc, VL_YELLOW);
Star2D (hdc, -5, -3, 0, 2, 2, 5);
Label2D (hdc, -5, -3, "Horizontal and vertical shear");
PopTransformation2D (NULL);
PushTransformation2D (NULL);
Shear2D (-5, 3, 45, 0.5f, 0);
BrushColor (hdc, VL_BROWN);
Star2D (hdc, -5, 3, 0, 2, 2, 5);
Label2D (hdc, -5, 3, "Horizontal shear along 45 degree");
PopTransformation2D (NULL);
}
void PointRotateTransf2D (HDC hdc)
{
SetTextAlign (hdc, TA_CENTER | TA_BOTTOM);
Label2D (hdc, 5, 3, "(5,3)");
SetTextAlign (hdc, TA_RIGHT | TA_BASELINE);
Label2D (hdc, -5, 3, "(-5,3)");
SetTextAlign (hdc, TA_CENTER | TA_TOP);
Label2D (hdc, -5, -3, "(-5,-3)");
SetTextAlign (hdc, TA_LEFT | TA_BASELINE);
Label2D (hdc, 5, -3, "(5,-3)");
SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
ViewerName (VL_CURRENT, "2D Point Ratate Transformation");
PenColor (hdc, VL_WHITE);
BrushColor (hdc, VL_RED);
Star2D (hdc, 0, 0, 0, 2, 2, 5);
Line2D (hdc, 5, 3, 0, 0);
Label2D (hdc, 0, 0, "Original");
PushTransformation2D (NULL);
PointRotate2D (5, 3, 90);
BrushColor (hdc, VL_GREEN);
Star2D (hdc, 0, 0, 0, 2, 2, 5);
LineTo2D (hdc, 0, 0);
LineTo2D (hdc, 5, 3);
Label2D (hdc, 0, 0, "Rotate 90 degree around (5,3)");
PopTransformation2D (NULL);
Line2D (hdc, -5, 3, 0, 0);
PushTransformation2D (NULL);
PointRotate2D (-5, 3, 45);
BrushColor (hdc, VL_YELLOW);
Star2D (hdc, 0, 0, 0, 2, 2, 5);
LineTo2D (hdc, 0, 0);
LineTo2D (hdc, -5, 3);
Label2D (hdc, 0, 0, "Rotate 45 degree around (-5,3)");
PopTransformation2D (NULL);
Line2D (hdc, 5, -3, 0, 0);
PushTransformation2D (NULL);
PointRotate2D (5, -3, 45);
BrushColor (hdc, VL_BLUE);
Star2D (hdc, 0, 0, 0, 2, 2, 5);
LineTo2D (hdc, 0, 0);
LineTo2D (hdc, 5, -3);
Label2D (hdc, 0, 0, "Rotate 45 degree around (5,-3)");
PopTransformation2D (NULL);
Line2D (hdc, -5, -3, 0, 0);
PushTransformation2D (NULL);
PointRotate2D (-5, -3, 90);
BrushColor (hdc, VL_BROWN);
Star2D (hdc, 0, 0, 0, 2, 2, 5);
LineTo2D (hdc, 0, 0);
LineTo2D (hdc, -5, -3);
Label2D (hdc, 0, 0, "Rotate 90 degree around (-5,-3)");
PopTransformation2D (NULL);
}
void PointScaleTransf2D (HDC hdc)
{
SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
BrushColor (hdc, VL_RED);
Star2D (hdc, 5, 3, 0, 2, 2, 5);
Label2D (hdc, 5, 3, "Original");
PushTransformation2D (NULL);
PointScale2D (0, 0, -1, 1);
BrushColor (hdc, VL_GREEN);
Star2D (hdc, 5, 3, 0, 2, 2, 5);
Label2D (hdc, 5, 3, "Horizontal flipped");
PopTransformation2D (NULL);
PushTransformation2D (NULL);
PointScale2D (0, 0, 1, -1);
BrushColor (hdc, VL_BLUE);
Star2D (hdc, 5, 3, 0, 2, 2, 5);
Label2D (hdc, 5, 3, "Vertical flipped");
PopTransformation2D (NULL);
PushTransformation2D (NULL);
PointScale2D (0, 0, -1, -1);
BrushColor (hdc, VL_YELLOW);
Star2D (hdc, 5, 3, 0, 2, 2, 5);
Label2D (hdc, 5, 3, "Horizontal and vertical flipped");
PopTransformation2D (NULL);
}
void Transformation2D (HDC hdc, WORD func)
{
TextColor (hdc, VL_BLACK, VL_NONE);
PushTransformation2D (NULL);
switch (func) {
case IDM_2DTRANSF_TRANSLATE:
TranslateTransf2D (hdc);
break;
case IDM_2DTRANSF_SCALE:
break;
case IDM_2DTRANSF_POINTSCALE:
PointScaleTransf2D (hdc);
break;
case IDM_2DTRANSF_ROTATE:
break;
case IDM_2DTRANSF_POINTROTATE:
PointRotateTransf2D (hdc);
break;
case IDM_2DTRANSF_STRETCH:
StretchTransf2D (hdc);
break;
case IDM_2DTRANSF_SHEAR:
ShearTransf2D (hdc);
break;
case IDM_2DTRANSF_MIRROR:
MirrorTransf2D (hdc);
break;
}
PopTransformation2D (NULL);
}
void AxleRotateTransf3D (HDC hdc)
{
WORD i;
VECTOR3 ref = {0, 0, 0}, dir;
char str[] = "Visualib";
SetTextAlign(hdc, TA_LEFT | TA_BOTTOM);
SetTextHeight (20);
MarkPosition3D (hdc, 0, 0, 0, 20, VL_ORIGIN);
BrushColor (hdc, VL_RED);
Text3D (hdc, 15, 15, 0, str);
VSET3 (dir, 1, 0, 0);
for (i = 1; i < 4; i++) {
PushTransformation3D (NULL);
AxleRotate3D (ref, dir, i * 90);
BrushColor (hdc, (WORD)(i+1));
Text3D (hdc, 15, 15, 0, str);
PopTransformation3D (NULL);
}
VSET3 (dir, 0, 1, 0);
for (i = 1; i < 4; i++) {
PushTransformation3D (NULL);
AxleRotate3D (ref, dir, i * 90);
BrushColor (hdc, (WORD)(i+4));
Text3D (hdc, 15, 15, 0, str);
PopTransformation3D (NULL);
}
VSET3 (dir, 1, -1, 0);
for (i = 1; i < 4; i++) {
PushTransformation3D (NULL);
AxleRotate3D (ref, dir, i * 90);
BrushColor (hdc, (WORD)(i+7));
Text3D (hdc, 15, 15, 0, str);
PopTransformation3D (NULL);
}
}
void StretchTransf3D (HDC hdc)
{
VECTOR3 ref = {0, 0, 0}, dir;
SetTextHeight (30);
SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
PushTransformation3D (NULL);
VSET3 (dir, -1, 1, 1);
Stretch3D (ref, dir, 1.5f);
Cube (hdc, 20, 20, 20);
MarkPosition3D (hdc, 0, 0, 0, 40, VL_ORIGIN);
PopTransformation3D (NULL);
}
void ShearTransf3D (HDC hdc)
{
VECTOR3 origin = {0, 0, 0}, normal = {0, 0, 1};
SetTextHeight (30);
SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
PushTransformation3D (NULL);
Shear3D (origin, normal, -0.5f, 0.5f);
Cube (hdc, 20, 20, 20);
MarkPosition3D (hdc, 0, 0, 0, 40, VL_ORIGIN);
PopTransformation3D (NULL);
}
void MirrorTransf3D (HDC hdc)
{
VECTOR3 ref = {0, 0, 0}, dir;
char str[] = "Visualib";
MarkPosition3D (hdc, 0, 0, 0, 40, VL_ORIGIN);
ViewerName (VL_CURRENT, "3D Mirror Transformation");
SetTextAlign (hdc, TA_LEFT | TA_BOTTOM);
SetTextHeight (20);
BrushColor (hdc, VL_RED);
Text3D (hdc, 3, 3, 0, str);
PushTransformation3D (NULL);
VSET3 (dir, 1, 0, 0);
Mirror3D (ref, dir);
BrushColor (hdc, VL_GREEN);
Text3D (hdc, 3, 3, 0, str);
PopTransformation3D (NULL);
PushTransformation3D (NULL);
VSET3 (dir, 0, 1, 0);
Mirror3D (ref, dir);
BrushColor (hdc, VL_YELLOW);
Text3D (hdc, 3, 3, 0, str);
PopTransformation3D (NULL);
PushTransformation3D (NULL);
VSET3 (dir, -1, -1, 0);
Mirror3D (ref, dir);
BrushColor (hdc, VL_BLUE);
Text3D (hdc, 3, 3, 0, str);
PopTransformation3D (NULL);
}
void PointScaleTransf3D (HDC hdc)
{
char str[] = "Visualib";
MarkPosition3D (hdc, 0, 0, 0, 40, VL_ORIGIN);
ViewerName (VL_CURRENT, "3D PointScale Transformation");
SetTextAlign (hdc, TA_LEFT | TA_BOTTOM);
SetTextHeight (20);
BrushColor (hdc, VL_RED);
Text3D (hdc, 3, 3, 0, str);
PushTransformation3D (NULL);
PointScale3D (0, 0, 0, -1, 1, 1);
BrushColor (hdc, VL_GREEN);
Text3D (hdc, 3, 3, 0, str);
PopTransformation3D (NULL);
PushTransformation3D (NULL);
PointScale3D (0, 0, 0, 1, -1, 1);
BrushColor (hdc, VL_YELLOW);
Text3D (hdc, 3, 3, 0, str);
PopTransformation3D (NULL);
PushTransformation3D (NULL);
PointScale3D (0, 0, 0, -1, -1, 1);
BrushColor (hdc, VL_BLUE);
Text3D (hdc, 3, 3, 0, str);
PopTransformation3D (NULL);
}
void Transformation3D (HDC hdc, int func)
{
TextColor (hdc, VL_WHITE, VL_NONE);
ClearDepthBuffer (0xffff);
switch (func) {
case IDM_3DTRANSF_TRANSLATE:
break;
case IDM_3DTRANSF_SCALE:
break;
case IDM_3DTRANSF_POINTSCALE:
PointScaleTransf3D (hdc);
break;
case IDM_3DTRANSF_ROTATE:
break;
case IDM_3DTRANSF_AXLEROTATE:
AxleRotateTransf3D (hdc);
break;
case IDM_3DTRANSF_STRETCH:
StretchTransf3D (hdc);
break;
case IDM_3DTRANSF_SHEAR:
ShearTransf3D (hdc);
break;
case IDM_3DTRANSF_MIRROR:
MirrorTransf3D (hdc);
break;
}
}
VOIDED MaterialPropertyDemo (HDC hdc)
{
WORD i, j, n = 1, shininess;
REAL ks, kd;
RECT rect;
HMATE hm = SelectMaterial (VL_CURRENT);
COLORREF diffuse, specular;
SwitchLight (light7, TRUE);
SwitchLight (light8, TRUE);
SelectViewer (VL_DEFAULT);
ViewerName (VL_CURRENT, "Material Reflection Property");
specular = MaterialSpecular (hm, VL_INQUIRE);
diffuse = MaterialDiffuse (hm, VL_INQUIRE);
shininess = MaterialShininess (hm, VL_INQUIRE);
rect.top = 10;
ks = 0.1f;
for (i = 0; i < 6; i++) {
kd = 0.05f;
rect.left = 10;
rect.bottom = rect.top + 40;
for (j = 0; j < 10; j++) {
rect.right = rect.left + 40;
MaterialShininess (hm, n);
MaterialSpecular (hm, ScaleColor (specular, ks));
MaterialDiffuse (VL_CURRENT, ScaleColor (diffuse, kd));
if (!ShadingPreview (hdc, &rect, 5, 173))
goto exit;
rect.left += 49;
kd += 0.1f;
}
ks += 0.2f;
rect.top += 53;
n *= 2;
}
exit:
MaterialDiffuse (hm, diffuse);
MaterialSpecular (hm, specular);
MaterialShininess (hm, shininess);
}
void CompositeDemo3D (HDC hdc)
{
REAL r0, r1, r2, t1, t2, h;
WORD i;
BOOL flag;
SelectViewer (VL_DEFAULT);
ViewerName (VL_DEFAULT, "Object Composition");
ClearDepthBuffer (0xffff);
SwitchLight (light7, TRUE);
SwitchLight (light8, TRUE);
SelectMaterial (VL_DEFAULT);
PushTransformation3D (NULL);
r0 = 4; r1 = 30; r2 = 40;
t1 = 3; t2 = 2; h = 10;
if (!SolidRing (hdc, r2, r2, t2, h, 115, 335, 1))
goto exit;
PushTransformation3D (NULL);
Translate3D (0, 0, h / 2);
SelectMaterial (mater1);
Rotate3D (135, 'z');
for (i = 0; i < 10; i++) {
PushTransformation3D (NULL);
Translate3D (35, 0, 0);
flag = Sphere (hdc, r0);
PopTransformation3D (NULL);
Rotate3D (20, 'z');
if (!flag)
goto exit;
}
PopTransformation3D (NULL);
SelectMaterial (VL_DEFAULT);
if (!Tube (hdc, r1, r1, t1, h))
goto exit;
PushTransformation3D (NULL);
Translate3D (0, 0, h / 2);
SelectMaterial (mater1);
Rotate3D (-25, 'z');
for (i = 0; i < 8; i++) {
PushTransformation3D (NULL);
Translate3D (35, 0, 0);
flag = Sphere (hdc, r0);
PopTransformation3D (NULL);
Rotate3D (20, 'z');
if (!flag)
break;
}
PopTransformation3D (NULL);
exit:
PopTransformation3D (NULL);
}
void DepthClippingDemo (HDC hdc)
{
HVIEW hv = VL_DEFAULT;
SelectViewer (hv);
SetPerspective (hv, 45, 1, 141, 200);
ClearDepthBuffer (0xffff);
SwitchLight (light7, TRUE);
SwitchLight (light8, TRUE);
SelectMaterial (mater1);
TranslateTo3D (20, 0, 0);
if (!Sphere (hdc, 20))
goto exit;
SelectMaterial (mater2);
TranslateTo3D (0, 20, 0);
if (!Sphere (hdc, 20))
goto exit;
SelectMaterial (mater3);
TranslateTo3D (0, 0, 20);
if (!Sphere (hdc, 20))
goto exit;
TranslateTo3D (0, 0, 0);
SelectMaterial (VL_DEFAULT);
Cube (hdc, 40, 40, 40);
exit:
SetPerspective (hv, 45, 1, 30, 1000);
ViewerName (hv, "Depth Buffer and Clipping");
}
void MarbleRingDemo (HDC hdc)
{
WORD texture;
SelectViewer (VL_DEFAULT);
ViewerName (VL_CURRENT, "Marble Ring");
ClearDepthBuffer (0xffff);
SelectMaterial (mater3);
texture = SolidTexture (VL_MARBLE);
MaterialSpecular (mater3, RGB (255, 255, 255));
SwitchLight (light7, TRUE);
SwitchLight (light8, TRUE);
Torus (hdc, 35, 5);
SolidTexture (texture);
}
void WoodSurfaceDemo (HDC hdc)
{
WORD texture;
POINT3D surf[36] = {
{0,0,0},{1,0,0},{2,0,0},{3,0,0},{4,0,0},{5,0,0},
{0,1,0},{1,1,0},{2,1,0},{3,1,0},{4,1,0},{5,1,0},
{0,2,0},{1,2,0},{2,2,9},{3,2,9},{4,2,0},{5,2,0},
{0,3,0},{1,3,0},{2,3,9},{3,3,9},{4,3,0},{5,3,0},
{0,4,0},{1,4,0},{2,4,0},{3,4,0},{4,4,0},{5,4,0},
{0,5,0},{1,5,0},{2,5,0},{3,5,0},{4,5,0},{5,5,0}};
REAL sknot[20] = {0,0,0,1,2,3,3,3};
REAL tknot[20] = {0,0,0,1,2,3,3,3};
SelectViewer (VL_DEFAULT);
ViewerName (VL_CURRENT, "Wood Surface");
ClearDepthBuffer (0xffff);
texture = SolidTexture (VL_WOODGRAIN);
SwitchLight (light7, TRUE);
SwitchLight (light8, TRUE);
Translate3D (-15, -15, 5);
Scale3D (10, 10, 5);
NURBSSurface (hdc, VL_3D, (VECTOR) surf, 6, 6, sknot, tknot, 4, 4);
SolidTexture (texture);
}
void GraniteCubeDemo (HDC hdc)
{
WORD texture;
WORD l8;
SelectViewer (VL_DEFAULT);
ViewerName (VL_CURRENT, "Granite Cube");
ClearDepthBuffer (0xffff);
texture = SolidTexture (VL_GRANITE);
SelectMaterial (VL_DEFAULT);
l8 = LightIntensity (light8, 2);
SwitchLight (light7, TRUE);
SwitchLight (light8, TRUE);
Cube (hdc, 30, 30, 30);
SolidTexture (texture);
LightIntensity (light8, l8);
}
void StereoTextDemo (HDC hdc)
{
SelectViewer (VL_DEFAULT);
SelectMaterial (mater3);
ClearDepthBuffer (0xffff);
SetTextHeight (40);
SetTextThickness (8);
SwitchLight (light4, TRUE);
SwitchLight (light7, TRUE);
SelectMaterial (VL_DEFAULT);
PushTransformation3D (NULL);
Rotate3D (135, 'z');
Rotate3D (90, 'x');
SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
SolidText (hdc, "Visualib");
PopTransformation3D (NULL);
ViewerName (VL_CURRENT, "Stereo Text");
}
void Welcome (HDC hdc)
{
char str[80];
SelectViewer (VL_DEFAULT2D);
SetTextAlign (hdc, TA_BASELINE | TA_CENTER);
SetTextHeight (4);
PenColor (hdc, VL_RED);
BrushColor (hdc, VL_YELLOW);
wsprintf (str, "Welcome\nto\nVisuaLib");
SetFont (NULL);
Text2D (hdc, 0, 0, 0, str);
}
void BumpyDonutDemo (HDC hdc)
{
WORD texture;
SelectViewer (VL_DEFAULT);
ViewerName (VL_CURRENT, "Bumpy Donut");
SelectMaterial (mater2);
ClearDepthBuffer (0xffff);
texture = SolidTexture (VL_BUMPY);
MaterialSpecular (mater2, RGB (255, 255, 255));
// SwitchLight (light7, TRUE);
SwitchLight (light8, TRUE);
Torus (hdc, 35, 10);
SolidTexture (texture);
}
void VlibDemo (HDC hdc, WORD func)
{
BOOL l0, l1, l2, l3;
BOOL twosideshade, backfaceoff;
l0 = SwitchLight (VL_DEFAULT, FALSE);
l1 = SwitchLight (light1, FALSE);
l2 = SwitchLight (light2, FALSE);
l3 = SwitchLight (light3, FALSE);
twosideshade = TwoSideShading (FALSE);
backfaceoff = BackFaceRemoval (TRUE);
switch (func) {
case IDM_DEMO_START:
Welcome (hdc);
break;
case IDM_DEMO_SPOTLIGHT:
SpotlightDemo (hdc);
break;
case IDM_DEMO_MATERIALPROPERTY:
MaterialPropertyDemo (hdc);
break;
case IDM_DEMO_IMAGEMAPPING:
ImageMappingDemo (hdc);
break;
case IDM_DEMO_DEPTHCLIPPING:
DepthClippingDemo (hdc);
break;
case IDM_DEMO_MARBLERING:
MarbleRingDemo (hdc);
break;
case IDM_DEMO_BUMPYDONUT:
BumpyDonutDemo (hdc);
break;
case IDM_DEMO_GRANITECUBE:
GraniteCubeDemo (hdc);
break;
case IDM_DEMO_WOODSURFACE:
WoodSurfaceDemo (hdc);
break;
case IDM_DEMO_3DCOMPOSITE:
CompositeDemo3D (hdc);
break;
case IDM_DEMO_STEREOTEXT:
StereoTextDemo (hdc);
break;
case IDM_DEMO_2DCOMPOSITE:
CompositeDemo2D (hdc);
break;
case IDM_DEMO_NURBSCURVE:
SelectViewer (VL_DEFAULT2D);
Primitives2D (hdc, IDM_2DCURVE_NURBS);
SelectViewer (VL_DEFAULT);
Primitives3D (hdc, IDM_3DCURVE_NURBS);
break;
case IDM_DEMO_POLYFACET:
SelectViewer (VL_DEFAULT);
ViewerName (VL_CURRENT, "Poly Facets");
PolyfacetsDemo (hdc);
break;
}
TwoSideShading (twosideshade);
BackFaceRemoval (backfaceoff);
SwitchLight (VL_DEFAULT, l0);
SwitchLight (light1, l1);
SwitchLight (light2, l2);
SwitchLight (light3, l3);
SwitchLight (light4, FALSE);
SwitchLight (light5, FALSE);
SwitchLight (light6, FALSE);
SwitchLight (light7, FALSE);
SwitchLight (light8, FALSE);
SelectMaterial (mater3);
}
void FunctionDemos (HDC hdc)
{
WORD func = demo_function;
SetROP2 (hdc, R2_COPYPEN);
if (func > IDM_2DPRIME_START && func < IDM_2DPRIME_END) {
SelectViewer (VL_DEFAULT2D);
Prime2D (hdc, func);
}
else if (func > IDM_3DPRIME_START && func < IDM_3DPRIME_END) {
SelectViewer (VL_DEFAULT);
Prime3D (hdc, func);
}
else if (func >= IDM_SURFACE_START && func < IDM_SURFACE_END) {
SelectViewer (VL_DEFAULT);
Surfaces (hdc, func);
}
else if (func >= IDM_SOLID_START && func < IDM_SOLID_END) {
SelectViewer (VL_DEFAULT);
ShowSolidPrimitives (hdc, func);
}
else if (func > IDM_ANIMATE_START && func < IDM_ANIMATE_END) {
AnimationDemo (hdc, func);
ViewerReset ();
SelectMaterial (mater3);
}
else if (func > IDM_TEXT_START && func < IDM_TEXT_END) {
ShowTextPrimitives (hdc, func);
}
else if (func > IDM_2DTRANSF_BEGIN && func < IDM_3DTRANSF_BEGIN) {
SelectViewer (VL_DEFAULT2D);
Transformation2D (hdc, func);
}
else if (func > IDM_3DTRANSF_BEGIN && func < IDM_3DTRANSF_END) {
SelectViewer (VL_DEFAULT);
Transformation3D (hdc, func);
}
else if (func > IDM_2DPRIMIT_START && func < IDM_2DPRIMIT_END) {
SelectViewer (VL_DEFAULT2D);
Primitives2D (hdc, func);
}
else if (func > IDM_3DPRIMIT_START && func < IDM_3DPRIMIT_END) {
SelectViewer (VL_DEFAULT);
Primitives3D (hdc, func);
}
else if (func > IDM_3DARRAY_BEGIN && func < IDM_3DARRAY_END) {
SelectViewer (VL_DEFAULT);
ObjectArray3D (hdc, func);
}
else if (func > IDM_2DARRAY_BEGIN && func < IDM_2DARRAY_END) {
SelectViewer (VL_DEFAULT2D);
ObjectArray2D (hdc, func);
}
else if (func / 100 == 20) {
SelectViewer (VL_DEFAULT);
ModellibDemo (hdc, func);
}
else {
VlibDemo (hdc, func);
}
PenColor (hdc, VL_BLUE);
DisplayViewerFrame (hdc, VL_CURRENT);
TextColor (hdc, VL_RED, VL_NONE);
DisplayViewerName (hdc, VL_CURRENT, FALSE);
}
void AdjustViewer (HWND hwnd, HVIEW hv)
{
RECT rect;
GetClientRect (hwnd, &rect);
rect.left += 10;
rect.right -= 10;
rect.top += 10;
rect.bottom -= 20;
SetViewerFrame (hv, &rect);
}
BOOLEAN SavePicture (HWND hwnd, BOOL withframe)
{
RECT rect;
HANDLE hdib;
BOOL flag;
GetScreenRect (hwnd, withframe, &rect);
hdib = ScreenToDIB (&rect);
if (!hdib)
return (FALSE);
flag = WriteDIBFile (NULL, hdib);
GlobalUnlock (hdib);
GlobalFree (hdib);
return (flag);
}
BOOLEAN PrintPicture (HWND hwnd, BOOL withframe)
{
RECT rect;
HANDLE hdib;
BOOL flag;
GetScreenRect (hwnd, withframe, &rect);
hdib = ScreenToDIB (&rect);
if (!hdib)
return (FALSE);
flag = PrintImage (hdib,
VL_BESTFIT | VL_VERTCENTER | VL_HORZCENTER | VL_MARKCORNER,
0, 0, 0, 0);
GlobalUnlock (hdib);
GlobalFree (hdib);
return (flag);
}
void PrintFlag (void)
{
SelectViewer (viewer22);
PrintDrawing (USFlag,
VL_BESTFIT | VL_HORZCENTER | VL_VERTCENTER | VL_MARKCORNER,
0, 0, 0, 0);
}
void ExitVlibDemo (HWND hwnd)
{
#ifndef WIN32
DeleteObject (GetClassWord (hwnd, GCW_HBRBACKGROUND));
#endif
ExitVisualib ();
if (hdib1) {
GlobalUnlock (hdib1);
GlobalFree (hdib1);
}
if (hdib2) {
GlobalUnlock (hdib2);
GlobalFree (hdib2);
}
if (hdib3) {
GlobalUnlock (hdib3);
GlobalFree (hdib3);
}
PostQuitMessage (0);
}
void AlterMenuItem (HWND hwnd, WORD entry)
{
WORD flag = MF_BYCOMMAND;
switch (entry) {
case IDM_DEMO_WITHFRAME:
withframe = !withframe;
flag |= (withframe) ? MF_CHECKED : MF_UNCHECKED;
break;
}
CheckMenuItem (GetMenu (hwnd), entry, flag);
}
/****************************************************************************
FUNCTION: MainWndProc (HWND, WORD, WORD, LONG)
****************************************************************************/
long WINAPI MainWndProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
switch (msg) {
case WM_COMMAND:
switch (wparam) {
case IDM_DEMO_EXIT:
PostMessage (hwnd, WM_DESTROY, 0, 0L);
break;
case IDM_HELP_ABOUT:
AboutVisualib ();
SendMessage (hwnd, WM_COMMAND, IDM_DEMO_START, 0L);
break;
case IDM_HELP_LICENSE:
LicenseInfo ();
break;
case IDM_HELP_DEMOPROG:
WinHelp (hwnd, "vlibdemo.hlp", HELP_INDEX, 0);
break;
case IDM_HELP_VISUALIB:
WinHelp (hwnd, "visualib.hlp", HELP_INDEX, 0);
break;
case IDM_DEMO_SAVEPICTURE:
SavePicture (hwnd, withframe);
break;
case IDM_DEMO_PRINTPICTURE:
PrintPicture (hwnd, withframe);
break;
case IDM_DEMO_WITHFRAME:
AlterMenuItem (hwnd, (WORD)wparam);
break;
case IDM_DEMO_PRINTFLAG:
PrintFlag ();
break;
case IDM_TEXT_SELECTFONT:
SelectTrueTypeFont ();
return (0);
default:
if (wparam > 200 && wparam < 300) {
ShadingSettings (hwnd, (WORD)wparam);
}
else {
demo_function = wparam;
InvalidateRect (hwnd, NULL, TRUE);
return (DefWindowProc (hwnd, msg, wparam, lparam));
}
}
break;
case WM_DESTROY:
ExitVlibDemo (hwnd);
break;
case WM_PAINT:
ProcessWindowPaint (hwnd);
break;
case WM_SIZE:
AdjustViewer (hwnd, VL_DEFAULT2D);
AdjustViewer (hwnd, VL_DEFAULT);
InvalidateRect (hwnd, NULL, TRUE);
break;
default:
return (DefWindowProc (hwnd, msg, wparam, lparam));
}
return (0);
}